package com.yangrong.thread.chapter12;

import java.io.IOException;
import java.util.Random;

public class ChangerThread extends Thread {

	private BalkingData data;

	private Random random = new Random();

	public ChangerThread(String name, BalkingData data) {
		super(name);
		this.data = data;
	}

	@Override
	public void run() {
		try {
			for (int i = 0; i < 20; i++) {
				data.change("No." + i);
				Thread.sleep(random.nextInt(1000));
				data.save();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
